import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:flutter/services.dart' show rootBundle;

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  Future<void> _uploadFile() async {
    try {
      // 1. 从 assets 读取文件为字节
      final byteData = await rootBundle.load('assets/files/test.txt');
      final bytes = byteData.buffer.asUint8List();

      // 2. 上传到 Supabase（直接传 Uint8List）
      await Supabase.instance.client.storage
          .from('storagegb')
          .uploadBinary('test.txt', bytes);

      debugPrint('控制台输出wenben文件上传成功！');
    } catch (e) {
      debugPrint('控制台输出wenben上传失败: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Bar文件wenben上传测试')),
      body: Center(
        child: ElevatedButton(
          onPressed: _uploadFile,
          child: Text('按钮点击上传wenben测试文件'),
        ),
      ),
    );
  }
}